{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:50:53.281029Z",
     "start_time": "2019-10-03T15:50:53.185572Z"
    }
   },
   "outputs": [],
   "source": [
    "import os, re, pickle, numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:50:54.701759Z",
     "start_time": "2019-10-03T15:50:54.126088Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "73\r\n"
     ]
    }
   ],
   "source": [
    "ls raw/concept_assertion_relation_training_data/beth/concept| wc -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:50:56.387400Z",
     "start_time": "2019-10-03T15:50:55.960811Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "97\r\n"
     ]
    }
   ],
   "source": [
    "ls raw/concept_assertion_relation_training_data/partners/concept| wc -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:50:58.037429Z",
     "start_time": "2019-10-03T15:50:57.602927Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0m\u001b[01;34mast\u001b[0m/  \u001b[01;34mconcept\u001b[0m/  \u001b[01;34mrel\u001b[0m/  \u001b[01;34mtxt\u001b[0m/\r\n"
     ]
    }
   ],
   "source": [
    "ls raw/concept_assertion_relation_training_data/beth/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:50:59.407222Z",
     "start_time": "2019-10-03T15:50:59.402358Z"
    }
   },
   "outputs": [],
   "source": [
    "TRAIN_DIRS = [\n",
    "    './raw/concept_assertion_relation_training_data/beth/',\n",
    "    './raw/concept_assertion_relation_training_data/partners/',\n",
    "]\n",
    "TEST_DIR = './raw/reference_standard_for_test_data/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:51:04.470172Z",
     "start_time": "2019-10-03T15:51:04.417417Z"
    }
   },
   "outputs": [],
   "source": [
    "def process_concept(concept_str):\n",
    "    \"\"\"\n",
    "    takes string like\n",
    "    'c=\"asymptomatic\" 16:2 16:2||t=\"problem\"'\n",
    "    and returns dictionary like\n",
    "    {'t': 'problem', 'start_line': 16, 'start_pos': 2, 'end_line': 16, 'end_pos': 2}\n",
    "    \"\"\"\n",
    "    try:\n",
    "        position_bit, problem_bit = concept_str.split('||')\n",
    "        t = problem_bit[3:-1]\n",
    "        \n",
    "        start_and_end_span = next(re.finditer('\\s\\d+:\\d+\\s\\d+:\\d+', concept_str)).span()\n",
    "        c = concept_str[3:start_and_end_span[0]-1]\n",
    "        c = [y for y in c.split(' ') if y.strip() != '']\n",
    "        c = ' '.join(c)\n",
    "\n",
    "        start_and_end = concept_str[start_and_end_span[0]+1 : start_and_end_span[1]]\n",
    "        start, end = start_and_end.split(' ')\n",
    "        start_line, start_pos = [int(x) for x in start.split(':')]\n",
    "        end_line, end_pos = [int(x) for x in end.split(':')]\n",
    "        \n",
    "        # Stupid and hacky!!!! This particular example raised a bug in my code below.\n",
    "#         if c == 'folate' and start_line == 43 and start_pos == 3 and end_line == 43 and end_pos == 3:\n",
    "#             start_pos, end_pos = 2, 2\n",
    "        \n",
    "    except:\n",
    "        print(concept_str)\n",
    "        raise\n",
    "    \n",
    "    return {\n",
    "        't': t, 'start_line': start_line, 'start_pos': start_pos, 'end_line': end_line, 'end_pos': end_pos,\n",
    "        'c': c, \n",
    "    }\n",
    "\n",
    "def build_label_vocab(base_dirs):\n",
    "    seen, label_vocab, label_vocab_size = set(['O']), {'O': 'O'}, 0\n",
    "    \n",
    "    for base_dir in base_dirs:\n",
    "        concept_dir = os.path.join(base_dir, 'concept')\n",
    "\n",
    "        assert os.path.isdir(concept_dir), \"Directory structure doesn't match!\"\n",
    "\n",
    "        ids = set([x[:-4] for x in os.listdir(concept_dir) if x.endswith('.con')])\n",
    "\n",
    "        for i in ids:\n",
    "            with open(os.path.join(concept_dir, '%s.con' % i)) as f:\n",
    "                concepts = [process_concept(x.strip()) for x in f.readlines()]\n",
    "            for c in concepts:\n",
    "                if c['t'] not in seen:\n",
    "                    label_vocab_size += 1\n",
    "                    label_vocab['B-%s' % c['t']] = 'B-%s' % c['t'] # label_vocab_size\n",
    "                    label_vocab_size += 1\n",
    "                    label_vocab['I-%s' % c['t']] = 'I-%s' % c['t'] # label_vocab_size\n",
    "                    seen.update([c['t']])\n",
    "    return label_vocab, label_vocab_size\n",
    "\n",
    "def reformatter(base, label_vocab, txt_dir = None, concept_dir = None):\n",
    "    if txt_dir is None: txt_dir = os.path.join(base, 'txt')\n",
    "    if concept_dir is None: concept_dir = os.path.join(base, 'concept')\n",
    "    \n",
    "    assert os.path.isdir(txt_dir) and os.path.isdir(concept_dir), \"Directory structure doesn't match!\"\n",
    "    \n",
    "    txt_ids = set([x[:-4] for x in os.listdir(txt_dir) if x.endswith('.txt')])\n",
    "    concept_ids = set([x[:-4] for x in os.listdir(concept_dir) if x.endswith('.con')])\n",
    "    \n",
    "    assert txt_ids == concept_ids, (\n",
    "        \"id set doesn't match: txt - concept = %s, concept - txt = %s\"\n",
    "        \"\" % (str(txt_ids - concept_ids), str(concept_ids - txt_ids))\n",
    "    )\n",
    "    \n",
    "    ids = txt_ids\n",
    "    \n",
    "    reprocessed_texts = {}\n",
    "    for i in ids:\n",
    "        with open(os.path.join(txt_dir, '%s.txt' % i), mode='r') as f:\n",
    "            lines = f.readlines()\n",
    "            txt = [[y for y in x.strip().split(' ') if y.strip() != ''] for x in lines]\n",
    "            line_starts_with_space = [x.startswith(' ') for x in lines]\n",
    "        with open(os.path.join(concept_dir, '%s.con' % i), mode='r') as f:\n",
    "            concepts = [process_concept(x.strip()) for x in f.readlines()]\n",
    "            \n",
    "        labels = [['O' for _ in line] for line in txt]\n",
    "        for c in concepts:\n",
    "            if c['start_line'] == c['end_line']:\n",
    "                line = c['start_line']-1\n",
    "                p_modifier = -1 if line_starts_with_space[line] else 0\n",
    "                text = (' '.join(txt[line][c['start_pos']+p_modifier:c['end_pos']+1+p_modifier])).lower()\n",
    "                assert text == c['c'], (\n",
    "                    \"Text mismatch! %s vs. %s (id: %s, line: %d)\\nFull line: %s\"\n",
    "                    \"\" % (c['c'], text, i, line, txt[line])\n",
    "                )\n",
    "                \n",
    "            for line in range(c['start_line']-1, c['end_line']):\n",
    "                p_modifier = -1 if line_starts_with_space[line] else 0\n",
    "                start_pos = c['start_pos']+p_modifier if line == c['start_line']-1 else 0\n",
    "                end_pos   = c['end_pos']+1+p_modifier if line == c['end_line']-1 else len(txt[line])\n",
    "                \n",
    "                if line == c['end_line'] - 1: labels[line][end_pos-1] = label_vocab['I-%s' % c['t']]                \n",
    "                if line == c['start_line'] - 1: labels[line][start_pos] = label_vocab['B-%s' % c['t']]\n",
    "                for j in range(start_pos + 1, end_pos-1): labels[line][j] = label_vocab['I-%s' % c['t']]\n",
    "            \n",
    "        joined_words_and_labels = [zip(txt_line, label_line) for txt_line, label_line in zip(txt, labels)]\n",
    "\n",
    "        out_str = '\\n\\n'.join(\n",
    "            ['\\n'.join(['%s %s' % p for p in joined_line]) for joined_line in joined_words_and_labels]\n",
    "        )\n",
    "        \n",
    "        reprocessed_texts[i] = out_str\n",
    "        \n",
    "    return reprocessed_texts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:51:07.369475Z",
     "start_time": "2019-10-03T15:51:06.938175Z"
    }
   },
   "outputs": [],
   "source": [
    "label_vocab, label_vocab_size = build_label_vocab([\n",
    "    'raw/concept_assertion_relation_training_data/beth/',\n",
    "    'raw/concept_assertion_relation_training_data/partners/',\n",
    "#     'raw/reference_standard_for_test_data/'\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:51:09.031392Z",
     "start_time": "2019-10-03T15:51:09.009718Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'O': 'O',\n",
       " 'B-test': 'B-test',\n",
       " 'I-test': 'I-test',\n",
       " 'B-problem': 'B-problem',\n",
       " 'I-problem': 'I-problem',\n",
       " 'B-treatment': 'B-treatment',\n",
       " 'I-treatment': 'I-treatment'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_vocab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:51:22.458917Z",
     "start_time": "2019-10-03T15:51:20.939484Z"
    }
   },
   "outputs": [],
   "source": [
    "reprocessed_texts = {\n",
    "    'beth':     reformatter('raw/concept_assertion_relation_training_data/beth/', label_vocab),\n",
    "    'partners': reformatter('raw/concept_assertion_relation_training_data/partners/', label_vocab),\n",
    "    'test':     reformatter(\n",
    "        'raw/reference_standard_for_test_data/', label_vocab,\n",
    "        txt_dir='raw/test_data/',\n",
    "        concept_dir='raw/reference_standard_for_test_data/concepts'\n",
    "    ),\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-03T15:51:26.385606Z",
     "start_time": "2019-10-03T15:51:26.378774Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "beth: 73\n",
      "partners: 97\n",
      "test: 256\n"
     ]
    }
   ],
   "source": [
    "for key, txt_by_record in reprocessed_texts.items(): print(\"%s: %d\" % (key, len(txt_by_record)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Admission O\n",
      "Date O\n",
      ": O\n",
      "\n",
      "2013-05-18 O\n",
      "\n",
      "Discharge O\n",
      "Date O\n",
      ": O\n",
      "\n",
      "2013-05-24 O\n",
      "\n",
      "Date O\n",
      "of O\n",
      "Birth O\n",
      ": O\n",
      "\n",
      "1811-08-19 O\n",
      "\n",
      "Sex O\n",
      ": O\n",
      "\n",
      "F O\n",
      "\n",
      "Service O\n",
      ": O\n",
      "\n",
      "MEDICINE O\n",
      "\n",
      "Allergies O\n",
      ": O\n",
      "\n",
      "Patient O\n",
      "recorded O\n",
      "as O\n",
      "having O\n",
      "No O\n",
      "Known B-problem\n",
      "Allergies I-problem\n",
      "to I-problem\n",
      "Drugs I-problem\n",
      "\n",
      "Attending O\n",
      ": O\n",
      "Sarah O\n",
      "Q. O\n",
      "George O\n",
      ", O\n",
      "M.D. O\n",
      "\n",
      "Chief O\n",
      "Complaint O\n",
      ": O\n",
      "\n",
      "Hip B-problem\n",
      "fracture I-problem\n",
      "\n",
      "Major O\n",
      "Surgical O\n",
      "or O\n",
      "Invasive O\n",
      "Procedure O\n",
      ": O\n",
      "\n",
      "OPERATIVE O\n",
      "PROCEDURE O\n",
      ": O\n",
      "\n",
      "1. O\n",
      "Closed B-treatment\n",
      "reduction I-treatment\n",
      "of I-treatment\n",
      "right I-treatment\n",
      "hip I-treatment\n",
      "with O\n",
      "open B-treatment\n",
      "placement I-treatment\n",
      "of I-treatment\n",
      "dynamic I-treatment\n",
      "hip I-treatment\n",
      "screw I-treatment\n",
      ", I-treatment\n",
      "right I-treatment\n",
      "hip I-treatment\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Examination B-test\n",
      "under I-test\n",
      "anesthesia I-test\n",
      "with O\n",
      "placement B-treatment\n",
      "of I-treatment\n",
      "splint I-treatment\n",
      ", I-treatment\n",
      "right I-treatment\n",
      "elbow I-treatment\n",
      ". O\n",
      "\n",
      "PROCEDURE O\n",
      "#2 O\n",
      ": O\n",
      "\n",
      "1. O\n",
      "Exploratory B-test\n",
      "laparotomy I-test\n",
      "with O\n",
      "drainage B-treatment\n",
      "of O\n",
      "intra-abdominal B-problem\n",
      "abscess I-problem\n",
      "and O\n",
      "peritonitis B-problem\n",
      "with O\n",
      "gross B-problem\n",
      "soilage I-problem\n",
      "with I-problem\n",
      "bile I-problem\n",
      "and I-problem\n",
      "gastric I-problem\n",
      "contents I-problem\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Exposure B-treatment\n",
      "and O\n",
      "wide B-treatment\n",
      "drainage I-treatment\n",
      "of O\n",
      "perforated B-problem\n",
      "posterior I-problem\n",
      "duodenal I-problem\n",
      "ulcer I-problem\n",
      "with O\n",
      "internal B-treatment\n",
      "and I-treatment\n",
      "external I-treatment\n",
      "drainage I-treatment\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Feeding B-treatment\n",
      "jejunostomy I-treatment\n",
      ". O\n",
      "\n",
      "4. O\n",
      "Tube B-treatment\n",
      "gastrostomy I-treatment\n",
      ". O\n",
      "\n",
      "5. O\n",
      "Placement O\n",
      "of O\n",
      "a B-treatment\n",
      "right I-treatment\n",
      "femoral I-treatment\n",
      "arterial I-treatment\n",
      "line I-treatment\n",
      ". O\n",
      "\n",
      "History O\n",
      "of O\n",
      "Present O\n",
      "Illness O\n",
      ": O\n",
      "\n",
      "90 O\n",
      "yo O\n",
      "F O\n",
      "with O\n",
      "MMP B-problem\n",
      "( O\n",
      "see O\n",
      "below O\n",
      ") O\n",
      "who O\n",
      "sustained O\n",
      "a B-problem\n",
      "mechanical I-problem\n",
      "fall I-problem\n",
      "down O\n",
      "stairs O\n",
      "resulting O\n",
      "in O\n",
      "a B-problem\n",
      "hip I-problem\n",
      "and I-problem\n",
      "arm I-problem\n",
      "fracture I-problem\n",
      ". O\n",
      "\n",
      "Fall B-problem\n",
      "was O\n",
      "witnessed O\n",
      "by O\n",
      "daughter O\n",
      ". O\n",
      "\n",
      "Nicholas B-problem\n",
      "seizures I-problem\n",
      ", O\n",
      "no O\n",
      "LOC B-problem\n",
      ", O\n",
      "no O\n",
      "head B-problem\n",
      "or I-problem\n",
      "neck I-problem\n",
      "trauma I-problem\n",
      ". O\n",
      "\n",
      "Patient O\n",
      "denies O\n",
      "CP B-problem\n",
      ", O\n",
      "SOB B-problem\n",
      ", O\n",
      "light B-problem\n",
      "headedness I-problem\n",
      ", O\n",
      "or O\n",
      "dizziness B-problem\n",
      "prior O\n",
      "to O\n",
      "of O\n",
      "after O\n",
      "the B-problem\n",
      "fall I-problem\n",
      ". O\n",
      "\n",
      "She O\n",
      "fell O\n",
      "on O\n",
      "her O\n",
      "R O\n",
      "side O\n",
      "and O\n",
      "had O\n",
      "a O\n",
      "great O\n",
      "deal O\n",
      "of O\n",
      "pain B-problem\n",
      "in I-problem\n",
      "her I-problem\n",
      "R I-problem\n",
      "arm I-problem\n",
      "and I-problem\n",
      "hip I-problem\n",
      ". O\n",
      "\n",
      "Presented O\n",
      "to O\n",
      "Taunton O\n",
      "and O\n",
      "found O\n",
      "to O\n",
      "have O\n",
      "R B-problem\n",
      "humerus I-problem\n",
      "and I-problem\n",
      "R I-problem\n",
      "hip I-problem\n",
      "fx I-problem\n",
      ". O\n",
      "\n",
      "Ct B-test\n",
      "of I-test\n",
      "head I-test\n",
      "and I-test\n",
      "neck I-test\n",
      "neg O\n",
      "for O\n",
      "fx B-problem\n",
      ", O\n",
      "bleed B-problem\n",
      ", O\n",
      "and O\n",
      "dislocation B-problem\n",
      ". O\n",
      "\n",
      "Past O\n",
      "Medical O\n",
      "History O\n",
      ": O\n",
      "\n",
      "1. O\n",
      "Coronary B-problem\n",
      "artery I-problem\n",
      "disease I-problem\n",
      "status O\n",
      "post O\n",
      "non-ST-elevation B-problem\n",
      "myocardial I-problem\n",
      "infarction I-problem\n",
      "in O\n",
      "2009-05-05 O\n",
      ", O\n",
      "status O\n",
      "post O\n",
      "cardiac B-test\n",
      "catheterization I-test\n",
      "with O\n",
      "left B-treatment\n",
      "anterior I-treatment\n",
      "descending I-treatment\n",
      "artery I-treatment\n",
      "stent I-treatment\n",
      "placement I-treatment\n",
      "in O\n",
      "05/2001 O\n",
      ". O\n",
      "\n",
      "2. O\n",
      "CHF B-problem\n",
      "with O\n",
      "an B-test\n",
      "ejection I-test\n",
      "fraction I-test\n",
      "of O\n",
      "40-45% O\n",
      "02-09 O\n",
      "\n",
      "3. O\n",
      "Diabetes B-problem\n",
      "type I-problem\n",
      "2 I-problem\n",
      ". O\n",
      "\n",
      "4. O\n",
      "Anemia B-problem\n",
      ", O\n",
      "transfusion B-problem\n",
      "dependent I-problem\n",
      "every O\n",
      "three O\n",
      "months O\n",
      ". O\n",
      "\n",
      "Hct B-test\n",
      "28 O\n",
      "b/l O\n",
      "\n",
      "5. O\n",
      "Polymyalgia B-problem\n",
      "rheumatica I-problem\n",
      ". O\n",
      "\n",
      "6. O\n",
      "Hypertension B-problem\n",
      ". O\n",
      "\n",
      "7. O\n",
      "Hypothyroidism B-problem\n",
      ". O\n",
      "\n",
      "8. O\n",
      "Chronic B-problem\n",
      "renal I-problem\n",
      "insufficiency I-problem\n",
      "with O\n",
      "a B-test\n",
      "b/l I-test\n",
      "creatinine I-test\n",
      "of O\n",
      "1.4 O\n",
      ". O\n",
      "\n",
      "9. O\n",
      "History O\n",
      "of O\n",
      "syncope B-problem\n",
      "and O\n",
      "first B-problem\n",
      "degree I-problem\n",
      "A-V I-problem\n",
      "heart I-problem\n",
      "block I-problem\n",
      "with O\n",
      "beta B-treatment\n",
      "blocker I-treatment\n",
      "therapy I-treatment\n",
      ". O\n",
      "\n",
      "10. O\n",
      "History O\n",
      "of O\n",
      "lower B-problem\n",
      "gastrointestinal I-problem\n",
      "bleed I-problem\n",
      "in O\n",
      "2009-06-05 O\n",
      ". O\n",
      "\n",
      "11. O\n",
      "spinal B-problem\n",
      "stenosis I-problem\n",
      "\n",
      "12. O\n",
      "Pacemaker B-treatment\n",
      "- O\n",
      "DDD B-treatment\n",
      "dual I-treatment\n",
      "chamber I-treatment\n",
      "rate I-treatment\n",
      "response I-treatment\n",
      "pacemaker I-treatment\n",
      "2011-08-22 O\n",
      "for O\n",
      "symptomatic B-problem\n",
      "bradycardia I-problem\n",
      "\n",
      "Social O\n",
      "History O\n",
      ": O\n",
      "\n",
      "Lives O\n",
      "alone O\n",
      "in O\n",
      "elderly O\n",
      "housing O\n",
      ", O\n",
      "a O\n",
      "daughter O\n",
      "in O\n",
      "the O\n",
      "area O\n",
      ", O\n",
      "two O\n",
      "children O\n",
      "and O\n",
      "exercises O\n",
      "two O\n",
      "times O\n",
      "a O\n",
      "week O\n",
      "by O\n",
      "walking O\n",
      "and O\n",
      "stretching O\n",
      ". O\n",
      "\n",
      "no O\n",
      ", O\n",
      "tob O\n",
      ", O\n",
      "no O\n",
      "etoh O\n",
      ", O\n",
      "no O\n",
      "drugs O\n",
      "\n",
      "Family O\n",
      "History O\n",
      ": O\n",
      "\n",
      "Noncontributory O\n",
      "\n",
      "Physical O\n",
      "Exam O\n",
      ": O\n",
      "\n",
      "at O\n",
      "admission O\n",
      "\n",
      "T B-test\n",
      "96.0 O\n",
      "BP B-test\n",
      "177/61 O\n",
      "P B-test\n",
      "70 O\n",
      "R B-test\n",
      "18 O\n",
      "O2 B-test\n",
      "97 O\n",
      "on O\n",
      "RA O\n",
      "\n",
      "Gen O\n",
      "- O\n",
      "somnolent B-problem\n",
      ", O\n",
      "confused B-problem\n",
      "\n",
      "HEENT O\n",
      "- O\n",
      "PERRL O\n",
      ", O\n",
      "OP O\n",
      "clear O\n",
      ", O\n",
      "EOMI O\n",
      "\n",
      "Cor O\n",
      "- O\n",
      "rrr O\n",
      ", O\n",
      "no O\n",
      "m/r/g B-problem\n",
      "\n",
      "Chest O\n",
      "- O\n",
      "CTAB O\n",
      "anteriorly O\n",
      "\n",
      "Abd O\n",
      "- O\n",
      "s/nt/nd B-problem\n",
      "+BS O\n",
      "\n",
      "Ext O\n",
      "- O\n",
      "2 O\n",
      "+ O\n",
      "edema B-problem\n",
      "to I-problem\n",
      "knees I-problem\n",
      ", O\n",
      "warm O\n",
      "2 O\n",
      "+ O\n",
      "pulses B-test\n",
      ", O\n",
      "pain B-problem\n",
      "in I-problem\n",
      "R I-problem\n",
      "arm I-problem\n",
      "and I-problem\n",
      "R I-problem\n",
      "hip I-problem\n",
      "\n",
      "Pertinent O\n",
      "Results O\n",
      ": O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "GLUCOSE B-test\n",
      "- O\n",
      "188 O\n",
      "* O\n",
      "UREA B-test\n",
      "N I-test\n",
      "- O\n",
      "48 O\n",
      "* O\n",
      "CREAT B-test\n",
      "- O\n",
      "1.3 O\n",
      "* O\n",
      "SODIUM B-test\n",
      "- O\n",
      "138 O\n",
      "POTASSIUM B-test\n",
      "- O\n",
      "4.0 O\n",
      "CHLORIDE B-test\n",
      "- O\n",
      "106 O\n",
      "TOTAL B-test\n",
      "CO2 I-test\n",
      "- O\n",
      "21 O\n",
      "* O\n",
      "ANION B-test\n",
      "GAP I-test\n",
      "- O\n",
      "15 O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "CK(CPK) B-test\n",
      "- O\n",
      "32 O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "CK-MB B-test\n",
      "- O\n",
      "NotDone O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "WBC B-test\n",
      "- O\n",
      "14.9 O\n",
      "*# O\n",
      "RBC B-test\n",
      "- O\n",
      "2.91 O\n",
      "* O\n",
      "HGB B-test\n",
      "- O\n",
      "8.5 O\n",
      "* O\n",
      "HCT B-test\n",
      "- O\n",
      "24.7 O\n",
      "* O\n",
      "MCV B-test\n",
      "- O\n",
      "85 O\n",
      "MCH B-test\n",
      "- O\n",
      "29.3 O\n",
      "MCHC B-test\n",
      "- O\n",
      "34.5 O\n",
      "RDW B-test\n",
      "- O\n",
      "14.6 O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "NEUTS B-test\n",
      "- O\n",
      "87.9 O\n",
      "* O\n",
      "BANDS B-test\n",
      "- O\n",
      "0 O\n",
      "LYMPHS B-test\n",
      "- O\n",
      "6.3 O\n",
      "* O\n",
      "MONOS B-test\n",
      "- O\n",
      "5.7 O\n",
      "EOS B-test\n",
      "- O\n",
      "0.1 O\n",
      "BASOS B-test\n",
      "- O\n",
      "0 O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "HYPOCHROM B-test\n",
      "- O\n",
      "1 O\n",
      "+ O\n",
      "ANISOCYT B-test\n",
      "- O\n",
      "NORMAL O\n",
      "POIKILOCY B-test\n",
      "- O\n",
      "NORMAL O\n",
      "MACROCYT B-test\n",
      "- O\n",
      "NORMAL O\n",
      "MICROCYT B-test\n",
      "- O\n",
      "NORMAL O\n",
      "POLYCHROM B-test\n",
      "- O\n",
      "NORMAL O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "PLT B-test\n",
      "SMR I-test\n",
      "- O\n",
      "NORMAL O\n",
      "PLT B-test\n",
      "COUNT I-test\n",
      "- O\n",
      "216 O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "PT B-test\n",
      "- O\n",
      "13.3 O\n",
      "PTT B-test\n",
      "- O\n",
      "26.4 O\n",
      "INR(PT) B-test\n",
      "- O\n",
      "1.2 O\n",
      "EKG B-test\n",
      "- O\n",
      "NSR O\n",
      "64 O\n",
      ", O\n",
      "1st B-problem\n",
      "deg I-problem\n",
      "block I-problem\n",
      ", O\n",
      "LAD B-problem\n",
      ", O\n",
      "new B-problem\n",
      "TWI I-problem\n",
      "inf/lat I-problem\n",
      "leads I-problem\n",
      ", O\n",
      "new B-problem\n",
      "ST I-problem\n",
      "depressions I-problem\n",
      "V4-6 I-problem\n",
      "\n",
      "Echo B-test\n",
      "02-09 O\n",
      "\n",
      "1. O\n",
      "The O\n",
      "left O\n",
      "atrium O\n",
      "is O\n",
      "moderately B-problem\n",
      "dilated I-problem\n",
      ". O\n",
      "\n",
      "The O\n",
      "left O\n",
      "atrium O\n",
      "is O\n",
      "elongated B-problem\n",
      ". O\n",
      "\n",
      "2. O\n",
      "The B-test\n",
      "left I-test\n",
      "ventricular I-test\n",
      "wall I-test\n",
      "thicknesses I-test\n",
      "are O\n",
      "normal O\n",
      ". O\n",
      "\n",
      "The B-test\n",
      "left I-test\n",
      "ventricular I-test\n",
      "cavity I-test\n",
      "size I-test\n",
      "is O\n",
      "normal O\n",
      ". O\n",
      "\n",
      "There O\n",
      "is O\n",
      "mild B-problem\n",
      "regional I-problem\n",
      "left I-problem\n",
      "ventricular I-problem\n",
      "systolic I-problem\n",
      "dysfunction I-problem\n",
      ". O\n",
      "\n",
      "Overall O\n",
      "left B-test\n",
      "ventricular I-test\n",
      "systolic I-test\n",
      "function I-test\n",
      "is O\n",
      "mildly B-problem\n",
      "depressed I-problem\n",
      ". O\n",
      "\n",
      "Resting B-problem\n",
      "regional I-problem\n",
      "wall I-problem\n",
      "motion I-problem\n",
      "abnormalities I-problem\n",
      "include O\n",
      "inferolateral B-problem\n",
      ", I-problem\n",
      "inferior I-problem\n",
      "and I-problem\n",
      "mid I-problem\n",
      "septal I-problem\n",
      "hypokinesis I-problem\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Right B-test\n",
      "ventricular I-test\n",
      "chamber I-test\n",
      "size I-test\n",
      "is O\n",
      "normal O\n",
      ". O\n",
      "\n",
      "Right B-test\n",
      "ventricular I-test\n",
      "systolic I-test\n",
      "function I-test\n",
      "is O\n",
      "normal O\n",
      ". O\n",
      "\n",
      "4. O\n",
      "The O\n",
      "aortic O\n",
      "valve O\n",
      "leaflets O\n",
      "( O\n",
      "3 O\n",
      ") O\n",
      "are O\n",
      "mildly B-problem\n",
      "thickened I-problem\n",
      ". O\n",
      "\n",
      "No O\n",
      "aortic B-problem\n",
      "regurgitation I-problem\n",
      "present O\n",
      ". O\n",
      "\n",
      "5. O\n",
      "The O\n",
      "mitral O\n",
      "valve O\n",
      "leaflets O\n",
      "are O\n",
      "mildly B-problem\n",
      "thickened I-problem\n",
      ". O\n",
      "\n",
      "Moderate B-problem\n",
      "( I-problem\n",
      "2 I-problem\n",
      "+) I-problem\n",
      "mitral I-problem\n",
      "regurgitation I-problem\n",
      "is O\n",
      "seen O\n",
      ". O\n",
      "\n",
      "6. O\n",
      "There O\n",
      "is O\n",
      "moderate B-problem\n",
      "pulmonary I-problem\n",
      "artery I-problem\n",
      "systolic I-problem\n",
      "hypertension I-problem\n",
      ". O\n",
      "\n",
      "7. O\n",
      "There O\n",
      "is O\n",
      "no O\n",
      "pericardial B-problem\n",
      "effusion I-problem\n",
      ". O\n",
      "\n",
      "Compared O\n",
      "with O\n",
      "the O\n",
      "findings O\n",
      "of O\n",
      "the B-test\n",
      "prior I-test\n",
      "study I-test\n",
      "( O\n",
      "tape O\n",
      "reviewed O\n",
      ") O\n",
      "of O\n",
      "2009-06-05 O\n",
      ", O\n",
      "the B-test\n",
      "LV I-test\n",
      "function I-test\n",
      "has O\n",
      "improved O\n",
      "with O\n",
      "an O\n",
      "improvementt O\n",
      "in O\n",
      "function O\n",
      "of O\n",
      "the O\n",
      "apex O\n",
      ", O\n",
      "septal O\n",
      "and O\n",
      "anterior O\n",
      "walls O\n",
      ". O\n",
      "\n",
      "New B-problem\n",
      "inferior I-problem\n",
      "and I-problem\n",
      "inferolateral I-problem\n",
      "wall I-problem\n",
      "motion I-problem\n",
      "abnormalities I-problem\n",
      "with O\n",
      "more B-problem\n",
      "severe I-problem\n",
      "mitral I-problem\n",
      "regurgitation I-problem\n",
      "present O\n",
      ". O\n",
      "\n",
      "Cath B-test\n",
      "2001 O\n",
      "\n",
      "1. O\n",
      "Coronary B-test\n",
      "angiography I-test\n",
      "demonstrated O\n",
      "single B-problem\n",
      "vessel I-problem\n",
      "disease I-problem\n",
      "in I-problem\n",
      "a I-problem\n",
      "right I-problem\n",
      "dominant I-problem\n",
      "system I-problem\n",
      ". O\n",
      "\n",
      "The O\n",
      "left O\n",
      "main O\n",
      "was O\n",
      "normal O\n",
      ". O\n",
      "\n",
      "The O\n",
      "LAD O\n",
      "had O\n",
      "serial B-problem\n",
      "90% I-problem\n",
      "lesions I-problem\n",
      "proximally I-problem\n",
      ", O\n",
      "involving O\n",
      "the O\n",
      "origin O\n",
      "of O\n",
      "the O\n",
      "first O\n",
      "diagonal O\n",
      ", O\n",
      "which O\n",
      "was O\n",
      "occluded B-problem\n",
      "and O\n",
      "filled O\n",
      "via O\n",
      "left O\n",
      "to O\n",
      "left O\n",
      "collaterals O\n",
      ". O\n",
      "\n",
      "The O\n",
      "mid-distal O\n",
      "LAD O\n",
      "was O\n",
      "underfilled B-problem\n",
      "initially O\n",
      "but O\n",
      "was O\n",
      "without O\n",
      "obstructive B-problem\n",
      "disease I-problem\n",
      ". O\n",
      "\n",
      "The O\n",
      "non-dominant O\n",
      "circumflex O\n",
      "system O\n",
      "had O\n",
      "no O\n",
      "hemodynamically B-problem\n",
      "significant I-problem\n",
      "stenoses I-problem\n",
      ". O\n",
      "\n",
      "The O\n",
      "dominant O\n",
      "RCA O\n",
      "was O\n",
      "a O\n",
      "large O\n",
      "vessel O\n",
      "with O\n",
      "no O\n",
      "significant B-problem\n",
      "disease I-problem\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Resting B-test\n",
      "hemodynamics I-test\n",
      "revealed O\n",
      "elevated B-problem\n",
      "right I-problem\n",
      "and I-problem\n",
      "left I-problem\n",
      "sided I-problem\n",
      "filling I-problem\n",
      "pressures I-problem\n",
      "with O\n",
      "a B-test\n",
      "mean I-test\n",
      "RA I-test\n",
      "pressure I-test\n",
      "of O\n",
      "12 O\n",
      "mm O\n",
      "Hg O\n",
      "and O\n",
      "a B-test\n",
      "mean I-test\n",
      "wedge I-test\n",
      "pressure I-test\n",
      "24 O\n",
      "mm O\n",
      "Hg O\n",
      ". O\n",
      "\n",
      "Moderate B-problem\n",
      "pulmonary I-problem\n",
      "hypertension I-problem\n",
      "was O\n",
      "present O\n",
      "with O\n",
      "a B-test\n",
      "PA I-test\n",
      "of O\n",
      "52/28 O\n",
      ". O\n",
      "\n",
      "The B-test\n",
      "cardiac I-test\n",
      "index I-test\n",
      "was O\n",
      "preserved O\n",
      "at O\n",
      "3.0 O\n",
      "L O\n",
      "/ O\n",
      "min O\n",
      "/ O\n",
      "m2 O\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Left B-test\n",
      "ventriculography I-test\n",
      "was O\n",
      "not O\n",
      "performed O\n",
      "due O\n",
      "to O\n",
      "the O\n",
      "presence O\n",
      "of O\n",
      "moderate B-problem\n",
      "renal I-problem\n",
      "insufficiency I-problem\n",
      "( O\n",
      "creatinine B-test\n",
      "1.6 O\n",
      "). O\n",
      "\n",
      "4. O\n",
      "Successful B-treatment\n",
      "PTCA I-treatment\n",
      "and O\n",
      "stenting B-treatment\n",
      "of I-treatment\n",
      "the I-treatment\n",
      "proximal I-treatment\n",
      "LAD I-treatment\n",
      "with O\n",
      "overlapping B-treatment\n",
      "2.25 I-treatment\n",
      "x I-treatment\n",
      "13 I-treatment\n",
      "mm I-treatment\n",
      "and I-treatment\n",
      "2.25 I-treatment\n",
      "x I-treatment\n",
      "18 I-treatment\n",
      "mm I-treatment\n",
      "Hepacoat I-treatment\n",
      "stents I-treatment\n",
      "with O\n",
      "no O\n",
      "residual B-problem\n",
      "stenosis I-problem\n",
      "or O\n",
      "dissection B-problem\n",
      "and O\n",
      "normal O\n",
      "flow O\n",
      "( O\n",
      "see O\n",
      "PTCA B-treatment\n",
      "comments O\n",
      "). O\n",
      "\n",
      "FINAL O\n",
      "DIAGNOSIS O\n",
      ": O\n",
      "\n",
      "1. O\n",
      "One B-problem\n",
      "vessel I-problem\n",
      "coronary I-problem\n",
      "artery I-problem\n",
      "disease I-problem\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Moderately B-problem\n",
      "elevated I-problem\n",
      "right I-problem\n",
      "and I-problem\n",
      "left I-problem\n",
      "sided I-problem\n",
      "filling I-problem\n",
      "pressures I-problem\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Successful B-treatment\n",
      "stenting I-treatment\n",
      "of I-treatment\n",
      "the I-treatment\n",
      "proximal I-treatment\n",
      "LAD I-treatment\n",
      ". O\n",
      "\n",
      "Hematology O\n",
      "\n",
      "COMPLETE B-test\n",
      "BLOOD I-test\n",
      "COUNT I-test\n",
      "WBC B-test\n",
      "RBC B-test\n",
      "Hgb B-test\n",
      "Hct B-test\n",
      "MCV B-test\n",
      "MCH B-test\n",
      "MCHC B-test\n",
      "RDW B-test\n",
      "Plt B-test\n",
      "Ct I-test\n",
      "\n",
      "2013-05-24 O\n",
      "09:40 O\n",
      "AM O\n",
      "19.3 O\n",
      "* O\n",
      "4.46 O\n",
      "13.1 O\n",
      "39.2 O\n",
      "88 O\n",
      "29.4 O\n",
      "33.5 O\n",
      "14.4 O\n",
      "159 O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "19.8 O\n",
      "*# O\n",
      "4.73 O\n",
      "13.8 O\n",
      "42.1 O\n",
      "# O\n",
      "89 O\n",
      "29.3 O\n",
      "32.9 O\n",
      "14.3 O\n",
      "147 O\n",
      "* O\n",
      "\n",
      "DIFFERENTIAL B-test\n",
      "Neuts B-test\n",
      "Bands B-test\n",
      "Lymphs B-test\n",
      "Monos B-test\n",
      "Eos B-test\n",
      "Baso B-test\n",
      "Atyps B-test\n",
      "Metas B-test\n",
      "\n",
      "2013-05-22 O\n",
      "06:15 O\n",
      "AM O\n",
      "90.0 O\n",
      "* O\n",
      "0 O\n",
      "5.6 O\n",
      "* O\n",
      "4.2 O\n",
      "0.1 O\n",
      "0.2 O\n",
      "\n",
      "RED B-test\n",
      "CELL I-test\n",
      "MORPHOLOGY I-test\n",
      "Hypochr B-test\n",
      "Anisocy B-test\n",
      "Poiklo B-test\n",
      "Macrocy B-test\n",
      "Microcy B-test\n",
      "Polychr B-test\n",
      "\n",
      "2013-05-22 O\n",
      "06:15 O\n",
      "AM O\n",
      "NORMAL O\n",
      "NORMAL O\n",
      "NORMAL O\n",
      "NORMAL O\n",
      "NORMAL O\n",
      "NORMAL O\n",
      "\n",
      "BASIC B-test\n",
      "COAGULATION I-test\n",
      "( O\n",
      "PT B-test\n",
      ", O\n",
      "PTT B-test\n",
      ", O\n",
      "PLT B-test\n",
      ", O\n",
      "INR B-test\n",
      ") O\n",
      "PT B-test\n",
      "PTT B-test\n",
      "Plt B-test\n",
      "Smr I-test\n",
      "Plt B-test\n",
      "Ct I-test\n",
      "INR(PT) B-test\n",
      "LPlt B-test\n",
      "\n",
      "2013-05-24 O\n",
      "09:40 O\n",
      "AM O\n",
      "159 O\n",
      "1 O\n",
      "+ O\n",
      "\n",
      "2013-05-24 O\n",
      "09:40 O\n",
      "AM O\n",
      "14.9 O\n",
      "* O\n",
      "1 O\n",
      "31.9 O\n",
      "1.5 O\n",
      "\n",
      "1 O\n",
      "NOTE O\n",
      "NEW O\n",
      "NORMAL O\n",
      "RANGE O\n",
      "AS O\n",
      "OF O\n",
      "12 O\n",
      "AM O\n",
      "2013-05-04 O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "147 O\n",
      "* O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "14.6 O\n",
      "* O\n",
      "1 O\n",
      "33.8 O\n",
      "1.4 O\n",
      "\n",
      "1 O\n",
      "NOTE O\n",
      "NEW O\n",
      "NORMAL O\n",
      "RANGE O\n",
      "AS O\n",
      "OF O\n",
      "12 O\n",
      "AM O\n",
      "2013-05-04 O\n",
      "\n",
      "Chemistry B-test\n",
      "\n",
      "RENAL O\n",
      "& O\n",
      "GLUCOSE O\n",
      "Glucose B-test\n",
      "UreaN B-test\n",
      "Creat B-test\n",
      "Na B-test\n",
      "K B-test\n",
      "Cl B-test\n",
      "HCO3 B-test\n",
      "AnGap B-test\n",
      "\n",
      "2013-05-24 O\n",
      "09:40 O\n",
      "AM O\n",
      "192 O\n",
      "* O\n",
      "87 O\n",
      "* O\n",
      "2.4 O\n",
      "* O\n",
      "146 O\n",
      "* O\n",
      "5.1 O\n",
      "114 O\n",
      "* O\n",
      "16 O\n",
      "* O\n",
      "21 O\n",
      "* O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "160 O\n",
      "* O\n",
      "86 O\n",
      "* O\n",
      "2.6 O\n",
      "* O\n",
      "148 O\n",
      "* O\n",
      "4.4 O\n",
      "115 O\n",
      "* O\n",
      "14 O\n",
      "* O\n",
      "1 O\n",
      "23 O\n",
      "* O\n",
      "\n",
      "1 O\n",
      "VERIFIED O\n",
      "BY O\n",
      "DILUTION O\n",
      "\n",
      "NOTIFIED O\n",
      "Y. O\n",
      "Welch O\n",
      "- O\n",
      "TSICU O\n",
      "140 O\n",
      "AM O\n",
      "2013-05-24 O\n",
      "\n",
      "ENZYMES B-test\n",
      "& O\n",
      "BILIRUBIN B-test\n",
      "ALT B-test\n",
      "AST B-test\n",
      "LD(LDH) B-test\n",
      "CK(CPK) B-test\n",
      "AlkPhos B-test\n",
      "Amylase B-test\n",
      "TotBili B-test\n",
      "DirBili B-test\n",
      "\n",
      "2013-05-24 O\n",
      "07:40 O\n",
      "AM O\n",
      "628 O\n",
      "* O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "22 O\n",
      "65 O\n",
      "* O\n",
      "739 O\n",
      "* O\n",
      "52 O\n",
      "81 O\n",
      "1.0 O\n",
      "\n",
      "OTHER B-test\n",
      "ENZYMES I-test\n",
      "& O\n",
      "BILIRUBINS B-test\n",
      "Lipase B-test\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "17 O\n",
      "\n",
      "CPK B-test\n",
      "ISOENZYMES B-test\n",
      "CK-MB B-test\n",
      "MB B-test\n",
      "Indx I-test\n",
      "cTropnT B-test\n",
      "\n",
      "2013-05-24 O\n",
      "07:40 O\n",
      "AM O\n",
      "15 O\n",
      "* O\n",
      "2.4 O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "14 O\n",
      "* O\n",
      "1.9 O\n",
      "0.12 O\n",
      "* O\n",
      "1 O\n",
      "\n",
      "1 O\n",
      "CTROPNT B-test\n",
      "> O\n",
      "0.10 O\n",
      "NG/ML O\n",
      "SUGGESTS O\n",
      "ACUTE B-problem\n",
      "MI I-problem\n",
      "\n",
      "CHEMISTRY B-test\n",
      "TotProt B-test\n",
      "Albumin B-test\n",
      "Globuln B-test\n",
      "Calcium B-test\n",
      "Phos B-test\n",
      "Mg B-test\n",
      "UricAcd B-test\n",
      "Iron B-test\n",
      "Cholest B-test\n",
      "\n",
      "2013-05-24 O\n",
      "09:40 O\n",
      "AM O\n",
      "8.3 O\n",
      "* O\n",
      "5.4 O\n",
      "* O\n",
      "2.1 O\n",
      "\n",
      "2013-05-24 O\n",
      "12:52 O\n",
      "AM O\n",
      "2.1 O\n",
      "* O\n",
      "7.7 O\n",
      "* O\n",
      "5.1 O\n",
      "*# O\n",
      "1.6 O\n",
      "\n",
      "LIPID B-test\n",
      "/ O\n",
      "CHOLESTEROL B-test\n",
      "Triglyc B-test\n",
      "HDL B-test\n",
      "CHOL/HD B-test\n",
      "LDLcalc B-test\n",
      "\n",
      "2013-05-19 O\n",
      "09:20 O\n",
      "AM O\n",
      "1603 O\n",
      "- O\n",
      "5419 O\n",
      "LDL(CALC) B-test\n",
      "INVALID O\n",
      "IF O\n",
      "TRIG B-test\n",
      "> O\n",
      "400 O\n",
      "OR O\n",
      "NON-FASTING O\n",
      "SAMPLE O\n",
      "LAB O\n",
      "USE O\n",
      "ONLY O\n",
      "GreenHd O\n",
      "\n",
      "2013-05-18 O\n",
      "06:00 O\n",
      "PM O\n",
      "HOLD1 O\n",
      "\n",
      "1 O\n",
      "HOLD O\n",
      "\n",
      "DISCARD O\n",
      "GREATER O\n",
      "THAN O\n",
      "4 O\n",
      "HOURS O\n",
      "OLD O\n",
      "\n",
      "Blood B-test\n",
      "Gas I-test\n",
      "\n",
      "BLOOD B-test\n",
      "GASES I-test\n",
      "Type B-test\n",
      "Temp B-test\n",
      "Rates B-test\n",
      "Tidal B-test\n",
      "V I-test\n",
      "PEEP B-test\n",
      "FiO2 B-test\n",
      "O2 B-test\n",
      "Flow B-test\n",
      "pO2 B-test\n",
      "pCO2 B-test\n",
      "pH B-test\n",
      "calHCO3 B-test\n",
      "Base B-test\n",
      "XS I-test\n",
      "AADO2 B-test\n",
      "REQ B-treatment\n",
      "O2 I-treatment\n",
      "Intubat B-treatment\n",
      "Vent B-treatment\n",
      "\n",
      "2013-05-24 O\n",
      "07:58 O\n",
      "AM O\n",
      "ART B-test\n",
      "102 O\n",
      "36 O\n",
      "7.26 O\n",
      "* O\n",
      "17 O\n",
      "* O\n",
      "-9 O\n",
      "\n",
      "2013-05-24 O\n",
      "04:31 O\n",
      "AM O\n",
      "ART B-test\n",
      "36.4 O\n",
      "16 O\n",
      "/ O\n",
      "662-15484 O\n",
      "* O\n",
      "7.26 O\n",
      "* O\n",
      "16 O\n",
      "* O\n",
      "-10 O\n",
      "\n",
      "ASSIST O\n",
      "/ O\n",
      "CON1 O\n",
      "INTUBATED B-treatment\n",
      "\n",
      "1 O\n",
      "ASSIST O\n",
      "/ O\n",
      "CONTROL O\n",
      "\n",
      "2013-05-24 O\n",
      "12:58 O\n",
      "AM O\n",
      "ART O\n",
      "147 O\n",
      "* O\n",
      "39 O\n",
      "7.22 O\n",
      "* O\n",
      "1 O\n",
      "17 O\n",
      "* O\n",
      "-11 O\n",
      "\n",
      "1 O\n",
      "VERIFIED O\n",
      "\n",
      "PROVIDER O\n",
      "NOTIFIED O\n",
      "PER O\n",
      "CURRENT O\n",
      "LAB O\n",
      "POLICY O\n",
      "\n",
      "WHOLE O\n",
      "BLOOD O\n",
      ", O\n",
      "MISCELLANEOUS B-test\n",
      "CHEMISTRY I-test\n",
      "Glucose B-test\n",
      "Lactate B-test\n",
      "Na B-test\n",
      "K B-test\n",
      "Cl B-test\n",
      "calHCO3 B-test\n",
      "\n",
      "2013-05-24 O\n",
      "07:58 O\n",
      "AM O\n",
      "4.5 O\n",
      "* O\n",
      "1 O\n",
      "\n",
      "1 O\n",
      "VERIFIED O\n",
      "\n",
      "2013-05-24 O\n",
      "04:31 O\n",
      "AM O\n",
      "5.1 O\n",
      "* O\n",
      "1 O\n",
      "\n",
      "1 O\n",
      "VERIFIED O\n",
      "\n",
      "2013-05-24 O\n",
      "12:58 O\n",
      "AM O\n",
      "6.2 O\n",
      "* O\n",
      "1 O\n",
      "\n",
      "1 O\n",
      "VERIFIED O\n",
      "\n",
      "HEMOGLOBLIN B-test\n",
      "FRACTIONS I-test\n",
      "( O\n",
      "COOXIMETRY B-test\n",
      ") O\n",
      "Hgb B-test\n",
      "calcHCT B-test\n",
      "O2 B-test\n",
      "Sat I-test\n",
      "COHgb B-test\n",
      "MetHgb B-test\n",
      "\n",
      "2013-05-23 O\n",
      "09:36 O\n",
      "PM O\n",
      "11.4 O\n",
      "* O\n",
      "34 O\n",
      "73 O\n",
      "1 O\n",
      "1 O\n",
      "\n",
      "2013-05-23 O\n",
      "01:08 O\n",
      "PM O\n",
      "10.9 O\n",
      "* O\n",
      "33 O\n",
      "96 O\n",
      "\n",
      "CALCIUM B-test\n",
      "freeCa B-test\n",
      "\n",
      "2013-05-23 O\n",
      "09:36 O\n",
      "PM O\n",
      "1.00 O\n",
      "* O\n",
      "\n",
      "2013-05-23 O\n",
      "01:08 O\n",
      "PM O\n",
      "1.22 O\n",
      "\n",
      "RADIOLOGY O\n",
      "Final O\n",
      "Report O\n",
      "\n",
      "CT B-test\n",
      "ABDOMEN I-test\n",
      "W/O I-test\n",
      "CONTRAST I-test\n",
      "2013-05-23 O\n",
      "5:46 O\n",
      "PM O\n",
      "\n",
      "CT B-test\n",
      "ABDOMEN I-test\n",
      "W/O I-test\n",
      "CONTRAST I-test\n",
      "; O\n",
      "CT B-test\n",
      "PELVIS I-test\n",
      "W/O I-test\n",
      "CONTRAST I-test\n",
      "\n",
      "Reason O\n",
      ": O\n",
      "Please O\n",
      "eval O\n",
      "for O\n",
      "perf B-problem\n",
      "/ I-problem\n",
      "ischemic I-problem\n",
      "bowel I-problem\n",
      "\n",
      "UNDERLYING O\n",
      "MEDICAL O\n",
      "CONDITION O\n",
      ": O\n",
      "\n",
      "92 O\n",
      "year O\n",
      "old O\n",
      "woman O\n",
      "with O\n",
      "MS B-problem\n",
      "changes I-problem\n",
      ", O\n",
      "abd B-problem\n",
      "pain I-problem\n",
      "hypotension B-problem\n",
      "and O\n",
      "bloody B-problem\n",
      "lavage I-problem\n",
      "on O\n",
      "Lovenox+ASA B-treatment\n",
      "\n",
      "REASON O\n",
      "FOR O\n",
      "THIS O\n",
      "EXAMINATION O\n",
      ": O\n",
      "\n",
      "Please O\n",
      "eval O\n",
      "for O\n",
      "perf B-problem\n",
      "/ I-problem\n",
      "ischemic I-problem\n",
      "bowel I-problem\n",
      "\n",
      "CONTRAINDICATIONS O\n",
      "for O\n",
      "IV B-test\n",
      "CONTRAST I-test\n",
      ": O\n",
      "renal B-problem\n",
      "failure I-problem\n",
      "\n",
      "INDICATION O\n",
      ": O\n",
      "94-year-old O\n",
      "woman O\n",
      "with O\n",
      "mental B-problem\n",
      "status I-problem\n",
      "changes I-problem\n",
      ", O\n",
      "now O\n",
      "with O\n",
      "abdominal B-problem\n",
      "pain I-problem\n",
      "and O\n",
      "hypertension B-problem\n",
      ". O\n",
      "\n",
      "TECHNIQUE O\n",
      ": O\n",
      "A O\n",
      "multidetector O\n",
      "scanner O\n",
      "was O\n",
      "used O\n",
      "to O\n",
      "obtain O\n",
      "contiguous B-test\n",
      "axial I-test\n",
      "images I-test\n",
      "from O\n",
      "the O\n",
      "lung O\n",
      "bases O\n",
      "to O\n",
      "the O\n",
      "pubic O\n",
      "symphysis O\n",
      ". O\n",
      "\n",
      "Neither O\n",
      "IV B-test\n",
      "nor I-test\n",
      "oral I-test\n",
      "contrast I-test\n",
      "were O\n",
      "used O\n",
      ". O\n",
      "\n",
      "CT B-test\n",
      "OF I-test\n",
      "THE I-test\n",
      "ABDOMEN I-test\n",
      "WITHOUT I-test\n",
      "IV I-test\n",
      "CONTRAST I-test\n",
      ": O\n",
      "There O\n",
      "are O\n",
      "bilateral B-problem\n",
      "pleural I-problem\n",
      "effusions I-problem\n",
      ", O\n",
      "right O\n",
      "greater O\n",
      "the O\n",
      "left O\n",
      "; O\n",
      "there O\n",
      "is O\n",
      "compressive B-problem\n",
      "atelectasis I-problem\n",
      "at I-problem\n",
      "the I-problem\n",
      "left I-problem\n",
      "lung I-problem\n",
      "base I-problem\n",
      ". O\n",
      "\n",
      "There O\n",
      "are O\n",
      "coronary B-problem\n",
      "vascular I-problem\n",
      "calcifications I-problem\n",
      ". O\n",
      "\n",
      "A B-treatment\n",
      "nasogastric I-treatment\n",
      "tube I-treatment\n",
      "is O\n",
      "seen O\n",
      "coiling O\n",
      "in O\n",
      "the O\n",
      "stomach O\n",
      ". O\n",
      "\n",
      "A B-treatment\n",
      "dual I-treatment\n",
      "chamber I-treatment\n",
      "pacemaker I-treatment\n",
      "is O\n",
      "seen O\n",
      "with O\n",
      "leads O\n",
      "terminating O\n",
      "in O\n",
      "the O\n",
      "right O\n",
      "atrium O\n",
      "and O\n",
      "right O\n",
      "ventricle O\n",
      ". O\n",
      "\n",
      "Nasogastric B-treatment\n",
      "tube I-treatment\n",
      "is O\n",
      "seen O\n",
      "coiling O\n",
      "in O\n",
      "the O\n",
      "stomach O\n",
      ", O\n",
      "with O\n",
      "its O\n",
      "tip O\n",
      "at O\n",
      "the O\n",
      "pylorus O\n",
      ". O\n",
      "\n",
      "Allowing O\n",
      "for O\n",
      "the O\n",
      "limitations O\n",
      "of O\n",
      "this B-test\n",
      "noncontrast I-test\n",
      "study I-test\n",
      ", O\n",
      "the O\n",
      "liver O\n",
      ", O\n",
      "pancreas O\n",
      ", O\n",
      "adrenals O\n",
      ", O\n",
      "stomach O\n",
      "are O\n",
      "unremarkable O\n",
      ". O\n",
      "\n",
      "A B-problem\n",
      "1.8 I-problem\n",
      "cm I-problem\n",
      "exophytic I-problem\n",
      "renal I-problem\n",
      "cyst I-problem\n",
      "is O\n",
      "seen O\n",
      "on O\n",
      "the O\n",
      "left O\n",
      ". O\n",
      "\n",
      "A B-problem\n",
      "similar I-problem\n",
      "lesion I-problem\n",
      "is O\n",
      "seen O\n",
      "on O\n",
      "the O\n",
      "right O\n",
      ", O\n",
      "measuring O\n",
      "2.2 O\n",
      "cm O\n",
      ". O\n",
      "\n",
      "The O\n",
      "aorta O\n",
      "is O\n",
      "normal O\n",
      "in O\n",
      "caliber O\n",
      ", O\n",
      "with O\n",
      "vascular B-problem\n",
      "calcifications I-problem\n",
      ". O\n",
      "\n",
      "A B-problem\n",
      "small I-problem\n",
      "amount I-problem\n",
      "of I-problem\n",
      "free I-problem\n",
      "fluid I-problem\n",
      "is O\n",
      "seen O\n",
      "tracking O\n",
      "around O\n",
      "the O\n",
      "liver O\n",
      ", O\n",
      "right O\n",
      "pericolic O\n",
      "gutter O\n",
      ", O\n",
      "along O\n",
      "the O\n",
      "mesentery O\n",
      "and O\n",
      "surrounding O\n",
      "the O\n",
      "right O\n",
      "colon O\n",
      ", O\n",
      "which O\n",
      "is O\n",
      "collapsed O\n",
      ". O\n",
      "\n",
      "A B-problem\n",
      "small I-problem\n",
      "amount I-problem\n",
      "of I-problem\n",
      "nondependent I-problem\n",
      "free I-problem\n",
      "air I-problem\n",
      "is O\n",
      "seen O\n",
      "in O\n",
      "the O\n",
      "anterior O\n",
      "aspect O\n",
      "of O\n",
      "the O\n",
      "abdomen O\n",
      ". O\n",
      "\n",
      "The O\n",
      "remainder O\n",
      "of O\n",
      "the O\n",
      "bowel O\n",
      "loops O\n",
      "are O\n",
      "fluid O\n",
      "filled O\n",
      ", O\n",
      "and O\n",
      "nondilated B-problem\n",
      ". O\n",
      "\n",
      "CT B-test\n",
      "OF I-test\n",
      "THE I-test\n",
      "PELVIS I-test\n",
      "WITHOUT I-test\n",
      "IV I-test\n",
      "CONTRAST I-test\n",
      ": O\n",
      "As O\n",
      "previously O\n",
      "noted O\n",
      ", O\n",
      "there O\n",
      "is O\n",
      "a B-problem\n",
      "small I-problem\n",
      "amount I-problem\n",
      "of I-problem\n",
      "free I-problem\n",
      "fluid I-problem\n",
      "surrounding O\n",
      "the O\n",
      "right O\n",
      "colon O\n",
      ", O\n",
      "tracking O\n",
      "along O\n",
      "the O\n",
      "mesentery O\n",
      "and O\n",
      "into O\n",
      "the O\n",
      "pelvis O\n",
      ". O\n",
      "\n",
      "A B-problem\n",
      "small I-problem\n",
      "amount I-problem\n",
      "of I-problem\n",
      "free I-problem\n",
      "air I-problem\n",
      "is O\n",
      "seen O\n",
      "in O\n",
      "the O\n",
      "nondependent O\n",
      "portion O\n",
      "of O\n",
      "the O\n",
      "pelvis O\n",
      ". O\n",
      "\n",
      "Vascular B-problem\n",
      "calcifications I-problem\n",
      "are O\n",
      "seen O\n",
      "in O\n",
      "the O\n",
      "abdominal O\n",
      "aorta O\n",
      "and O\n",
      "iliac O\n",
      "arteries O\n",
      ". O\n",
      "\n",
      "Subcutaneous B-problem\n",
      "edema I-problem\n",
      "is O\n",
      "noted O\n",
      "in O\n",
      "the O\n",
      "lower O\n",
      "abdomen O\n",
      "and O\n",
      "pelvis O\n",
      ". O\n",
      "\n",
      "A B-treatment\n",
      "catheter I-treatment\n",
      "is O\n",
      "seen O\n",
      "entering O\n",
      "the O\n",
      "left O\n",
      "inguinal O\n",
      "region O\n",
      "and O\n",
      "coursing O\n",
      "along O\n",
      "the O\n",
      "iliac O\n",
      "vessels O\n",
      ", O\n",
      "terminating O\n",
      "in O\n",
      "the O\n",
      "left O\n",
      "pelvis O\n",
      ". O\n",
      "\n",
      "Osseous O\n",
      "structures O\n",
      "are O\n",
      "remarkable O\n",
      "for O\n",
      "degenerative B-problem\n",
      "changes I-problem\n",
      "of I-problem\n",
      "the I-problem\n",
      "spine I-problem\n",
      ", O\n",
      "and O\n",
      "a B-problem\n",
      "fracture I-problem\n",
      "of I-problem\n",
      "the I-problem\n",
      "proximal I-problem\n",
      "right I-problem\n",
      "humerus I-problem\n",
      ", O\n",
      "with O\n",
      "orthopedic B-treatment\n",
      "hardware I-treatment\n",
      "causing O\n",
      "beam B-problem\n",
      "hardening I-problem\n",
      "artifact I-problem\n",
      ". O\n",
      "\n",
      "IMPRESSION O\n",
      ": O\n",
      "\n",
      "1. O\n",
      "A O\n",
      "small O\n",
      "amount O\n",
      "of O\n",
      "free B-problem\n",
      "air I-problem\n",
      "and I-problem\n",
      "free I-problem\n",
      "fluid I-problem\n",
      "in I-problem\n",
      "the I-problem\n",
      "pelvis I-problem\n",
      "and I-problem\n",
      "abdomen I-problem\n",
      ", O\n",
      "mostly O\n",
      "along O\n",
      "the O\n",
      "right O\n",
      "pericolic O\n",
      "gutter O\n",
      "and O\n",
      "surrounding O\n",
      "the O\n",
      "ascending O\n",
      "colon O\n",
      ", O\n",
      "concerning O\n",
      "for O\n",
      "perforation B-problem\n",
      ". O\n",
      "\n",
      "Other O\n",
      "bowel O\n",
      "loops O\n",
      "are O\n",
      "unremarkable O\n",
      "on O\n",
      "this B-test\n",
      "limited I-test\n",
      "study I-test\n",
      ". O\n",
      "\n",
      "This O\n",
      "was O\n",
      "discussed O\n",
      "with O\n",
      "Dr. O\n",
      "Jason O\n",
      "Long O\n",
      "at O\n",
      "approximately O\n",
      "6:30 O\n",
      "p.m. O\n",
      ", O\n",
      "2013-05-23 O\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Bilateral B-problem\n",
      "pleural I-problem\n",
      "effusions I-problem\n",
      ", O\n",
      "right O\n",
      "greater O\n",
      "than O\n",
      "left O\n",
      ", O\n",
      "with O\n",
      "left-sided B-problem\n",
      "compressive I-problem\n",
      "atelectasis I-problem\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Right B-problem\n",
      "proximal I-problem\n",
      "humeral I-problem\n",
      "fracture I-problem\n",
      "status O\n",
      "post O\n",
      "fixation B-treatment\n",
      ". O\n",
      "\n",
      "The B-test\n",
      "study I-test\n",
      "and O\n",
      "the O\n",
      "report O\n",
      "were O\n",
      "reviewed O\n",
      "by O\n",
      "the O\n",
      "staff O\n",
      "radiologist O\n",
      ". O\n",
      "\n",
      "DR. O\n",
      "Billy O\n",
      "L. O\n",
      "Boender O\n",
      "\n",
      "DR. O\n",
      "Pat O\n",
      "K. O\n",
      "Walton O\n",
      "\n",
      "Approved O\n",
      ": O\n",
      "FRI O\n",
      "2013-05-24 O\n",
      "4:01 O\n",
      "PM O\n",
      "\n",
      "Brief O\n",
      "Hospital O\n",
      "Course O\n",
      ": O\n",
      "\n",
      "95 O\n",
      "yo O\n",
      "F O\n",
      "with O\n",
      "MMP B-problem\n",
      "who O\n",
      "sustained O\n",
      "a B-problem\n",
      "mechanical I-problem\n",
      "fall I-problem\n",
      "down O\n",
      "stairs O\n",
      "resulting O\n",
      "in O\n",
      "a B-problem\n",
      "hip I-problem\n",
      "and I-problem\n",
      "arm I-problem\n",
      "fracture I-problem\n",
      ". O\n",
      "\n",
      "1) O\n",
      "s/p O\n",
      "Fall B-problem\n",
      "- O\n",
      "unlikely O\n",
      "to O\n",
      "be O\n",
      "mechanical O\n",
      "in O\n",
      "nature O\n",
      ". O\n",
      "\n",
      "Patient O\n",
      "has O\n",
      "injuries B-problem\n",
      "to I-problem\n",
      "her I-problem\n",
      "shoulder I-problem\n",
      "and I-problem\n",
      "hip I-problem\n",
      ". O\n",
      "\n",
      "2) O\n",
      "CV O\n",
      "- O\n",
      "Patient O\n",
      "has O\n",
      "CAD B-problem\n",
      "and O\n",
      "CHF B-problem\n",
      "with O\n",
      "a B-problem\n",
      "low I-problem\n",
      "hct I-problem\n",
      "and O\n",
      "major B-problem\n",
      "trauma I-problem\n",
      ". O\n",
      "\n",
      "She O\n",
      "also O\n",
      "has O\n",
      "new B-problem\n",
      "changes I-problem\n",
      "on I-problem\n",
      "EKG I-problem\n",
      ". O\n",
      "\n",
      "On O\n",
      "pressor B-treatment\n",
      "to O\n",
      "hold O\n",
      "mean O\n",
      "60 O\n",
      ". O\n",
      "\n",
      "3) O\n",
      "Anemia B-problem\n",
      "- O\n",
      "patient O\n",
      "transfusion B-problem\n",
      "dependant I-problem\n",
      "with O\n",
      "a O\n",
      "baseline O\n",
      "of O\n",
      "28 O\n",
      ". O\n",
      "\n",
      "- O\n",
      "transfuse O\n",
      "2 O\n",
      "units O\n",
      "today O\n",
      ", O\n",
      "with O\n",
      "lasix B-treatment\n",
      "\n",
      "4) O\n",
      "GERD B-problem\n",
      "- O\n",
      "PPI B-treatment\n",
      "\n",
      "5) O\n",
      "DM B-problem\n",
      "- O\n",
      "glipizide B-treatment\n",
      ", O\n",
      "ISS B-treatment\n",
      "\n",
      "6) O\n",
      "PMR B-problem\n",
      "- O\n",
      "cont O\n",
      "prednisone B-treatment\n",
      "\n",
      "7) O\n",
      "GI O\n",
      ": O\n",
      "Ms. O\n",
      "Pimental O\n",
      "is O\n",
      "an O\n",
      "unfortunate O\n",
      "95 O\n",
      "year O\n",
      "old O\n",
      "woman O\n",
      ", O\n",
      "status O\n",
      "post O\n",
      "a B-problem\n",
      "recent I-problem\n",
      "fall I-problem\n",
      "necessitating O\n",
      "right B-treatment\n",
      "ORIF I-treatment\n",
      "of I-treatment\n",
      "the I-treatment\n",
      "hip I-treatment\n",
      "and O\n",
      "right B-problem\n",
      "wrist I-problem\n",
      "fracture I-problem\n",
      "ORIF B-treatment\n",
      ", O\n",
      "who O\n",
      "was O\n",
      "in O\n",
      "the O\n",
      "hospital O\n",
      "for O\n",
      "this O\n",
      "event O\n",
      ", O\n",
      "when O\n",
      "it O\n",
      "was O\n",
      "noted O\n",
      "that O\n",
      "she O\n",
      "had O\n",
      "abdominal B-problem\n",
      "pain I-problem\n",
      ", O\n",
      "distention B-problem\n",
      "and O\n",
      "coffee B-problem\n",
      "ground I-problem\n",
      "emesis I-problem\n",
      "with O\n",
      "worsening B-problem\n",
      "mental I-problem\n",
      "status I-problem\n",
      "and O\n",
      "renal B-problem\n",
      "failure I-problem\n",
      ". O\n",
      "\n",
      "CT B-test\n",
      "scan I-test\n",
      "was O\n",
      "obtained O\n",
      "and O\n",
      "this O\n",
      "revealed O\n",
      "free B-problem\n",
      "air I-problem\n",
      "and O\n",
      "massive B-problem\n",
      "ascites I-problem\n",
      ". O\n",
      "\n",
      "Pt O\n",
      "underwent O\n",
      "surgery B-treatment\n",
      "on O\n",
      "05-23 O\n",
      "\n",
      "1. O\n",
      "Exploratory B-test\n",
      "laparotomy I-test\n",
      "with O\n",
      "drainage B-treatment\n",
      "of O\n",
      "intra-abdominal B-problem\n",
      "abscess I-problem\n",
      "and O\n",
      "peritonitis B-problem\n",
      "with O\n",
      "gross B-problem\n",
      "soilage I-problem\n",
      "with I-problem\n",
      "bile I-problem\n",
      "and I-problem\n",
      "gastric I-problem\n",
      "contents I-problem\n",
      ". O\n",
      "\n",
      "2. O\n",
      "Exposure B-treatment\n",
      "and O\n",
      "wide B-treatment\n",
      "drainage I-treatment\n",
      "of O\n",
      "perforated B-problem\n",
      "posterior I-problem\n",
      "duodenal I-problem\n",
      "ulcer I-problem\n",
      "with O\n",
      "internal B-treatment\n",
      "and I-treatment\n",
      "external I-treatment\n",
      "drainage I-treatment\n",
      ". O\n",
      "\n",
      "3. O\n",
      "Feeding B-treatment\n",
      "jejunostomy I-treatment\n",
      ". O\n",
      "\n",
      "4. O\n",
      "Tube B-treatment\n",
      "gastrostomy I-treatment\n",
      ". O\n",
      "\n",
      "Continue O\n",
      "to O\n",
      "deteriorate O\n",
      "spiking B-problem\n",
      "fevers I-problem\n",
      "with O\n",
      "ventilatory B-treatment\n",
      "support I-treatment\n",
      "on O\n",
      "pressors B-treatment\n",
      "to O\n",
      "hold O\n",
      "the B-test\n",
      "bp. I-test\n",
      "with O\n",
      "no O\n",
      "improvement O\n",
      "in O\n",
      "mental O\n",
      "staus O\n",
      "was O\n",
      "made O\n",
      "CMO O\n",
      "5/20/5 O\n",
      ". O\n",
      "\n",
      "Expired O\n",
      "at O\n",
      "5 O\n",
      "pm O\n",
      "\n",
      "Medications O\n",
      "on O\n",
      "Admission O\n",
      ": O\n",
      "\n",
      "lasix B-treatment\n",
      "alt O\n",
      "40 O\n",
      "mg O\n",
      "and O\n",
      "20 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "levothyrox B-treatment\n",
      "50 O\n",
      "mcg O\n",
      "qday O\n",
      "\n",
      "lisinopril B-treatment\n",
      "5 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "famotidine B-treatment\n",
      "20 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "fe B-treatment\n",
      "so4 I-treatment\n",
      "325 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "asa B-treatment\n",
      "325 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "toprol B-treatment\n",
      "xl I-treatment\n",
      "25 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "glipizide B-treatment\n",
      "5 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "imdur B-treatment\n",
      "60 O\n",
      "mg O\n",
      "qdau O\n",
      "\n",
      "prednisone B-treatment\n",
      "5 O\n",
      "mg O\n",
      "qday O\n",
      "\n",
      "tylenol B-treatment\n",
      "\n",
      "Discharge O\n",
      "Disposition O\n",
      ": O\n",
      "\n",
      "Expired B-problem\n",
      "\n",
      "Discharge O\n",
      "Diagnosis O\n",
      ": O\n",
      "\n",
      "MULTIORGAN B-problem\n",
      "FAILURE I-problem\n",
      "\n",
      "DUODENAL B-problem\n",
      "PERFORATION I-problem\n",
      "\n",
      "MULTIPLE B-problem\n",
      "TRAUMA I-problem\n",
      "\n",
      "Discharge O\n",
      "Condition O\n",
      ": O\n",
      "\n",
      "deceased O\n",
      "\n",
      "Followup O\n",
      "Instructions O\n",
      ": O\n",
      "\n",
      "none O\n",
      "\n",
      "Frank O\n",
      "Linda O\n",
      "MD O\n",
      "44-897 O\n",
      "\n",
      "Completed O\n",
      "by O\n",
      ": O\n",
      "Deanna O\n",
      "Patague O\n",
      "MD O\n",
      "48-130 O\n",
      "2013-05-24 O\n",
      "@ O\n",
      "1820 O\n",
      "\n",
      "Signed O\n",
      "electronically O\n",
      "by O\n",
      ": O\n",
      "DR. O\n",
      "Marta O\n",
      "Keever O\n",
      "on O\n",
      ": O\n",
      "FRI O\n",
      "2013-06-21 O\n",
      "9:40 O\n",
      "PM O\n",
      "\n",
      "( O\n",
      "End O\n",
      "of O\n",
      "Report O\n",
      ") O\n"
     ]
    }
   ],
   "source": [
    "print(reprocessed_texts['beth']['record-37'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_partners_train_ids = np.random.permutation(list(reprocessed_texts['partners'].keys()))\n",
    "N = len(all_partners_train_ids)\n",
    "N_train = int(0.9 * N)\n",
    "\n",
    "partners_train_ids = all_partners_train_ids[:N_train]\n",
    "partners_dev_ids = all_partners_train_ids[N_train:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Partners # Patients: Train: 87, Dev: 10\n"
     ]
    }
   ],
   "source": [
    "print(\"Partners # Patients: Train: %d, Dev: %d\" %(len(partners_train_ids), len(partners_dev_ids)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_beth_train_ids = np.random.permutation(list(reprocessed_texts['beth'].keys()))\n",
    "N = len(all_beth_train_ids)\n",
    "N_train = int(0.9 * N)\n",
    "\n",
    "beth_train_ids = all_beth_train_ids[:N_train]\n",
    "beth_dev_ids = all_beth_train_ids[N_train:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Beth # Patients: Train: 65, Dev: 8\n"
     ]
    }
   ],
   "source": [
    "print(\"Beth # Patients: Train: %d, Dev: %d\" % (len(beth_train_ids), len(beth_dev_ids)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Merged # Patients: Train: 152, Dev: 18\n"
     ]
    }
   ],
   "source": [
    "print(\"Merged # Patients: Train: %d, Dev: %d\" % (\n",
    "  len(partners_train_ids) + len(beth_train_ids), len(beth_dev_ids) + len(partners_dev_ids)\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "merged_train_txt = '\\n\\n'.join(np.random.permutation(\n",
    "    [reprocessed_texts['partners'][i] for i in partners_train_ids] + \n",
    "    [reprocessed_texts['beth'][i] for i in beth_train_ids]\n",
    "))\n",
    "merged_dev_txt = '\\n\\n'.join(np.random.permutation(\n",
    "    [reprocessed_texts['partners'][i] for i in partners_dev_ids] + \n",
    "    [reprocessed_texts['beth'][i] for i in beth_dev_ids]\n",
    "))\n",
    "merged_test_txt = '\\n\\n'.join(np.random.permutation(list(reprocessed_texts['test'].values())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Merged # Samples: Train: 14251, Dev: 2064, Test: 27626\n"
     ]
    }
   ],
   "source": [
    "print(\"Merged # Samples: Train: %d, Dev: %d, Test: %d\" % (\n",
    "    len(merged_train_txt.split('\\n\\n')),\n",
    "    len(merged_dev_txt.split('\\n\\n')),\n",
    "    len(merged_test_txt.split('\\n\\n'))\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "partners_train_txt = '\\n\\n'.join(np.random.permutation(\n",
    "    [reprocessed_texts['partners'][i] for i in partners_train_ids]\n",
    "))\n",
    "partners_dev_txt = '\\n\\n'.join(np.random.permutation(\n",
    "    [reprocessed_texts['partners'][i] for i in partners_dev_ids]\n",
    "))\n",
    "partners_test_txt = '\\n\\n'.join(np.random.permutation(list(reprocessed_texts['test'].values())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "OUT_FILES = {\n",
    "    'merged_train': './processed/merged/train.tsv',\n",
    "    'merged_dev':   './processed/merged/dev.tsv',\n",
    "    'merged_test':  './processed/merged/test.tsv', \n",
    "    'partners_train': './processed/partners/train.tsv',\n",
    "    'partners_dev':   './processed/partners/dev.tsv',\n",
    "    'partners_test':  './processed/partners/test.tsv', \n",
    "    'vocab': './processed/label_vocab.pkl'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(OUT_FILES['merged_train'], mode='w') as f: f.write(merged_train_txt)\n",
    "with open(OUT_FILES['merged_dev'], mode='w') as f: f.write(merged_dev_txt)\n",
    "with open(OUT_FILES['merged_test'], mode='w') as f: f.write(merged_test_txt)\n",
    "with open(OUT_FILES['partners_train'], mode='w') as f: f.write(partners_train_txt)\n",
    "with open(OUT_FILES['partners_dev'], mode='w') as f: f.write(partners_dev_txt)\n",
    "with open(OUT_FILES['partners_test'], mode='w') as f: f.write(partners_test_txt)\n",
    "with open(OUT_FILES['vocab'], mode='wb') as f: pickle.dump(label_vocab, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
